// Copyright 2022 NullPTR. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

class UTexture2D;

/**
 * 
 */
class FRGBABitmap
{

public:
	/*
	 * 默认构造函数，w和h都为0，pBuffer为null
	 */
	FRGBABitmap();

	/*
	 * 创建像素行数为h，列数为w的黑色图像
	 */
	FRGBABitmap(int w, int h);

	/*
	 * 创建像素行数为h，列数为w的图像，并用pDataBuf中的数据进行填充，每个像素占用32位
	 */
	FRGBABitmap(int w, int h, void* pDataBuf);
	
	~FRGBABitmap();

	/*
	 * 创建像素行数为h，列数为w的黑色图像
	 */
	void Create(int w, int h);

	int16 GetWidth() const { return Width; }
	int16 GetHeight() const { return Height; }

	/*
	 * 获取坐标（x,y）的像素颜色，原点是左上角
	 */
	void GetRGBA(int x, int y, unsigned char &r, unsigned char &g, unsigned char &b, unsigned char &a) const;
	void GetRGB(int x, int y, unsigned char &r, unsigned char &g, unsigned char &b) const;

	/*
	 * 设置坐标（x,y）的像素颜色，原点是左上角
	 */
	void SetRGBA(int x, int y, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
	void SetRGB(int x, int y, unsigned char r, unsigned char g, unsigned char b);

	const TArray<FColor>& GetData() const;
	
	/*
	 * 把图像数据复制到UTexture2D纹理对象中
	 */
	UTexture2D* ToUTexture2D();

private:
	TArray<FColor> ImageData;
	int16 Width;
	int16 Height;
};
